package com.empire.module.spider.service.lotteryfootballgamezucaittg;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.empire.module.spider.controller.app.lotteryfootballgamezucaittg.vo.*;
import com.empire.module.spider.dal.dataobject.lotteryfootballgamezucaittg.LotteryFootballGameZucaiTtgDO;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.util.object.BeanUtils;

import com.empire.module.spider.dal.mysql.lotteryfootballgamezucaittg.LotteryFootballGameZucaiTtgMapper;

import static com.empire.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.empire.module.spider.enums.ErrorCodeConstants.*;

/**
 * 足彩4场总进球游戏 Service 实现类
 *
 * @author 无敌
 */
@Service
@Validated
public class LotteryFootballGameZucaiTtgServiceImpl implements LotteryFootballGameZucaiTtgService {

    @Resource
    private LotteryFootballGameZucaiTtgMapper lotteryFootballGameZucaiTtgMapper;

    @Override
    public String createLotteryFootballGameZucaiTtg(AppLotteryFootballGameZucaiTtgSaveReqVO createReqVO) {
        // 插入
        LotteryFootballGameZucaiTtgDO lotteryFootballGameZucaiTtg = BeanUtils.toBean(createReqVO, LotteryFootballGameZucaiTtgDO.class);
        lotteryFootballGameZucaiTtgMapper.insert(lotteryFootballGameZucaiTtg);
        // 返回
        return lotteryFootballGameZucaiTtg.getFid();
    }

    @Override
    public void updateLotteryFootballGameZucaiTtg(AppLotteryFootballGameZucaiTtgSaveReqVO updateReqVO) {
        // 校验存在
        validateLotteryFootballGameZucaiTtgExists(updateReqVO.getFid());
        // 更新
        LotteryFootballGameZucaiTtgDO updateObj = BeanUtils.toBean(updateReqVO, LotteryFootballGameZucaiTtgDO.class);
        lotteryFootballGameZucaiTtgMapper.updateById(updateObj);
    }

    @Override
    public void deleteLotteryFootballGameZucaiTtg(String id) {
        // 校验存在
        validateLotteryFootballGameZucaiTtgExists(id);
        // 删除
        lotteryFootballGameZucaiTtgMapper.deleteById(id);
    }

    private void validateLotteryFootballGameZucaiTtgExists(String id) {
        if (lotteryFootballGameZucaiTtgMapper.selectById(id) == null) {
            throw exception(LOTTERY_FOOTBALL_GAME_ZUCAI_TTG_NOT_EXISTS);
        }
    }

    @Override
    public LotteryFootballGameZucaiTtgDO getLotteryFootballGameZucaiTtg(String id) {
        return lotteryFootballGameZucaiTtgMapper.selectById(id);
    }

    @Override
    public PageResult<LotteryFootballGameZucaiTtgDO> getLotteryFootballGameZucaiTtgPage(AppLotteryFootballGameZucaiTtgPageReqVO pageReqVO) {
        return lotteryFootballGameZucaiTtgMapper.selectPage(pageReqVO);
    }

}
